home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / select-to-pattern.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  3.0 KB  |  88 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Based on select-to-brush by
  4. ;     Copyright (c) 1997 Adrian Likins aklikins@eos.ncsu.edu
  5. ; Author Cameron Gregory, http://www.flamingtext.com/
  6. ;
  7. ; Takes the current selection, saves it as a pattern and makes it the active
  8. ; pattern
  9. ;
  10. ; This program is free software; you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation; either version 2 of the License, or
  13. ; (at your option) any later version.
  14. ; This program is distributed in the hope that it will be useful,
  15. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ; GNU General Public License for more details.
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program; if not, write to the Free Software
  20. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  
  23. (define (script-fu-selection-to-pattern image drawable desc filename)
  24.  
  25.   (if (= (car (gimp-selection-is-empty image)) TRUE)
  26.       (begin
  27.     (set! selection-width (car (gimp-drawable-width drawable)))
  28.     (set! selection-height (car (gimp-drawable-height drawable))))
  29.       (begin
  30.     (set! selection-bounds (gimp-drawable-mask-bounds drawable))
  31.     (set! select-offset-x (cadr selection-bounds))
  32.     (set! select-offset-y (caddr selection-bounds))
  33.     (set! selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
  34.     (set! selection-height (- (caddr (cddr selection-bounds)) select-offset-y))))
  35.  
  36.   (if (= (car (gimp-drawable-has-alpha drawable)) TRUE)
  37.       (set! pattern-draw-type RGBA-IMAGE)
  38.       (set! pattern-draw-type RGB-IMAGE))
  39.  
  40.   (set! pattern-image-type RGB)
  41.  
  42.   (set! pattern-image (car (gimp-image-new selection-width selection-height
  43.                        pattern-image-type)))
  44.  
  45.   (set! pattern-draw
  46.     (car (gimp-layer-new pattern-image selection-width selection-height
  47.                  pattern-draw-type "Pattern" 100 NORMAL-MODE)))
  48.  
  49.   (gimp-drawable-fill pattern-draw TRANSPARENT-FILL)
  50.  
  51.   (gimp-image-add-layer pattern-image pattern-draw 0)
  52.  
  53.   (gimp-edit-copy drawable)
  54.  
  55.   (let ((floating-sel (car (gimp-edit-paste pattern-draw FALSE))))
  56.     (gimp-floating-sel-anchor floating-sel))
  57.  
  58.   (set! filename2 (string-append gimp-directory
  59.                  "/patterns/"
  60.                  filename
  61.                  (number->string image)
  62.                  ".pat"))
  63.  
  64.   (file-pat-save 1 pattern-image pattern-draw filename2 "" desc)
  65.   (gimp-patterns-refresh)
  66.   (gimp-context-set-pattern desc)
  67.  
  68.   (gimp-image-delete pattern-image)
  69.   (gimp-displays-flush))
  70.  
  71. (script-fu-register "script-fu-selection-to-pattern"
  72.             _"To _Pattern..."
  73.             "Convert a selection to a pattern"
  74.             "Cameron Gregory <cameron@bloke.com>"
  75.             "Cameron Gregory"
  76.             "09/02/2003"
  77.             "RGB* GRAY*"
  78.             SF-IMAGE    "Image"         0
  79.             SF-DRAWABLE "Drawable"      0
  80.             SF-STRING   _"Pattern name" "My Pattern"
  81.             SF-STRING   _"Filename"     "mypattern")
  82.  
  83. (script-fu-menu-register "script-fu-selection-to-pattern"
  84.              _"<Image>/Script-Fu/Selection")
  85.